//
// Created by tao on 24-11-7.
//
#include "random.h"

#include <stdlib.h>
#include <time.h>
static ADC_HandleTypeDef *adc_handle;

void Random_Init(ADC_HandleTypeDef *hadc) {
    adc_handle = hadc;
    HAL_ADCEx_Calibration_Start(hadc);
    HAL_ADC_Start(hadc);
    srand(HAL_ADC_GetValue(adc_handle));
}

/**
 *
 * @return [min, max]
 */
int rand_range(const int min, const int max) {
    int result = rand() % (max - min + 1) + min;
    srand(HAL_ADC_GetValue(adc_handle));
    return result;
}
